#include <iostream>
#include <unistd.h>
using namespace std;
int gcd(int a,int b)
{
    return b == 0? a:gcd(b,a%b);
}//计算最大公约数
string getdes_path(int p,int q)
{
    if(p == 1&&q == 1)
    {
        return "";
    }
    int leftden = 1;int rightden = 0;
    int leftnum = 0;int rightnum = 1;
    string ret;
    //mid_num/mid_den = p/q
    while(true)
    {
        int mid_den = (leftden+rightden);
        int mid_num = (leftnum+rightnum);
        //midnum/midden = p/q
        if(mid_num*q == mid_den*p)
        {
            return ret;
        }
        else if(mid_num*q<mid_den*p)
        {
            leftden = mid_den;
            leftnum = mid_num;
            ret+="R";
        }
        else 
        {
            rightden = mid_den;
            rightnum = mid_num;
            ret+="L";
        }
    }
}
int main() {
    //在二叉搜索树中找到某一个特定的值，可以通过二分查找的方法来解决，这道题目首先记录下左分数的分母和分子，
    int p;int q;cin>>p>>q;
    int g = gcd(p,q);
    p/=g;
    q/=g;
    string ret = getdes_path(p,q);
    int row = ret.size()+1;//层数得到
    int position = 0;
    for(char c:ret)//二进制快速得到节点在某一层的序号
    {
        position = (position<<1)|(c == 'R'?1:0);
    }
    position+=1;
    cout<<row<<" "<<position<<endl;
    return 0;
}
// 64 位输出请用 printf("%lld")